Skip to content

Optimize GetBindingsForConstructor(): memoize Type.GetMembers() result - #527

Merged
SergeiPavlov merged 3 commits into
master-servicetitanfrom
GetBindingsForConstructor
Sep 29, 2026
Merged

SergeiPavlov merged 3 commits into
master-servicetitanfrom
GetBindingsForConstructor

Conversation

@SergeiPavlov

@SergeiPavlov SergeiPavlov commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

According to the core dumps this is a bottleneck:

00007F40437F8E28 00007f50aa01530e [DynamicHelperFrame: 00007f40437f8e28] 
00007F40437F8F00 00007F506F169636 System.RuntimeType.GetMembers(System.Reflection.BindingFlags)
00007F40437F8FF0 00007F50731597E1 Xtensive.Orm.Linq.Translator.GetBindingsForConstructor(System.Reflection.ParameterInfo[], System.Collections.Generic.IReadOnlyList`1<System.Linq.Expressions.Expression>, System.Linq.Expressions.Expression)

Also:

  • Simplify FilterBindings()

Note

Low Risk
Localized LINQ translator optimization with a minor string-comparison tweak; no auth, persistence, or API surface changes.

Overview
Speeds up LINQ new/constructor translation by caching Type.GetMembers() per type in GetBindingsForConstructor() via Memoizer, instead of calling reflection on every constructor binding pass (the hotspot called out in profiling).

FilterBindings() is rewritten as a compact expression-bodied helper with a switch on field vs property; member name matching now uses OrdinalIgnoreCase instead of InvariantCultureIgnoreCase (same intent for typical identifiers, slightly different rules for culture-sensitive casing).

Reviewed by Cursor Bugbot for commit a37bdf3. Bugbot is set up for automated code reviews on this repo. Configure here.

@snaumenko-st snaumenko-st left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to remove culture specific comparison as well

@SergeiPavlov
SergeiPavlov merged commit b779cb6 into master-servicetitan Sep 29, 2026
35 checks passed
@SergeiPavlov
SergeiPavlov deleted the GetBindingsForConstructor branch September 29, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants